package com.itheima.app.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.app.manager.SoulQuestionManager;
import com.itheima.domain.db.Answers;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SoulQuestionController {

    @Autowired
    SoulQuestionManager soulQuestionManager;

    /**
     * 测灵魂-问卷列表
     * @return
     */
    @GetMapping("/testSoul")
    public ResponseEntity testSoul(){
        return soulQuestionManager.testSoul();
    }


    /**
     * 提交问卷
     * @param answers
     * @return
     */
    @PostMapping("/testSoul")
    public ResponseEntity commitQuestion(@RequestBody String answers){
        List<Answers> answersList = JSON.parseArray(JSON.parseObject(answers).getString("answers"), Answers.class);
        return soulQuestionManager.commitQuestion(answersList);
    }

    /**
     * 报告列表
     * @param reportId
     * @return
     */
    @GetMapping("/testSoul/report/{reportId}")
    public ResponseEntity findReportById(@PathVariable Integer reportId){
        return soulQuestionManager.findReportById(reportId);
    }

}
